<?php 
if(KT!='KhiThe') exit;
class categorys_model extends khithe_mysql{

	public function getMenuProducts($ParentID,$ispage=null)
	{
        $qr = empty($ispage)?NULL:" AND IsPage!='".$ispage."' ";
		$ParentID = parent::checkStrMySQL($ParentID);
		$ispage . $select = "SELECT * FROM ".categorys." WHERE ParentID = '".$ParentID."' $qr ORDER BY `Order` ASC";
		parent::CloseConnection();
		return parent::SelectMySQL($select);
	}
    public function getMenuCom()
	{
		$select = "SELECT * FROM ".components." ORDER BY `Order` ASC";
		parent::CloseConnection();
		return parent::SelectMySQL($select);
	}
	
	public function getMenu($ID)
	{
		$ID = parent::checkStrMySQL($ID);
		$select = "SELECT * FROM ".categorys." WHERE ID = '".$ID."'";
		parent::CloseConnection();
		return parent::SelectMySQL($select);
	}
	
	public function setCheckedMenu($ID,$Val)
	{
		$ID = parent::checkStrMySQL($ID);
		$update = "UPDATE ".categorys." SET Status='".$Val."'  WHERE ID = '".$ID."'";
		parent::CloseConnection();
		return parent::UpdateInsertMySQL($update);
	}

    public function mdc_set_order($arr_id=0)
    {
        $rs ='';
        foreach($arr_id as $key => $id)
        {
            $key = $key+1;
            $key = parent::mysql_check_string($key);
            $id = parent::mysql_check_string($id);
            $select = "UPDATE ". prefix ."categories SET ". prefix ."categories.Order='$key' WHERE `ID` = '$id'";
            $rs = parent::mysql_update_insert($select);
        }
        return $rs;
    }

	public function setOrderMenu($arr_id)
	{
        foreach($arr_id as $key => $ID)
        {
            $key = $key+1;
            $ID = parent::checkStrMySQL($ID);
            $update = "UPDATE ".categorys." SET `Order`='".$key."'  WHERE ID = '".$ID."'";
            parent::CloseConnection();
            $done =  parent::UpdateInsertMySQL($update);
        }
        return $done;
	}

	public function delCheckedMenu($ID)
	{
		$ID = parent::checkStrMySQL($ID);
		$del = "DELETE FROM ".categorys." WHERE ID='".$ID."' ";
		parent::CloseConnection();
		return parent::DeleteMySQL($del);
	}
	
	public function mdcheckSeoKey($SeoKey)
	{
		$SeoKey = parent::checkStrMySQL($SeoKey);
		$select = "SELECT * FROM ".categorys." WHERE SeoKey = '".$SeoKey."'";
		$resultSql= parent::SelectMySQL($select);
		$total = mysql_num_rows($resultSql);
		parent::CloseConnection();
		return $total;
	}
	
	public function updateInsertCat($arr)
	{
		$CatID = parent::checkStrMySQL($arr['CategoryID']);
		$CatName = parent::checkStrMySQL($arr['CategoryName']);
		$Order = parent::checkStrMySQL($arr['CatOrder']);
		$PrentID = parent::checkStrMySQL($arr['parentCatID']);
		/*SEO*/
		$SeoKey = parent::checkStrMySQL($arr['seo_key']);
		$TitlePage = parent::checkStrMySQL($arr['title_page']);
		$KeyWords = parent::checkStrMySQL($arr['keywords']);
		$Description = parent::checkStrMySQL($arr['description']);
		$SeoH1 = parent::checkStrMySQL($arr['seo_h1']);
		$SeoH2 = parent::checkStrMySQL($arr['seo_h2']);
		$SeoP = parent::checkStrMySQL($arr['seo_p']);
		$comp = parent::checkStrMySQL($arr['comp']);

		$h_menu = parent::checkStrMySQL($arr['h_menu']);
		$v_menu = parent::checkStrMySQL($arr['v_menu']);
		$is_page = parent::checkStrMySQL($arr['is_page']);


		
		
		if($this->valUrl(1)=='edit'){
			$query = "UPDATE ".categorys." SET Category='".$CatName."',comp='".$comp."',`Order`='".trim($Order)."', ParentID ='".$PrentID."',SeoKey='".$SeoKey."',TitlePage = '".trim($TitlePage)."',Description = '".$Description."',KeyWords = '".$KeyWords."',SeoH1 = '".$SeoH1."',SeoH2 = '".$SeoH2."',SeoP = '".$SeoP."',MenuV = '".$v_menu."',MenuH = '".$h_menu."',IsPage = '".$is_page."' WHERE ID = '".trim($CatID)."'";
		
		}else if($this->valUrl(1)=='add'){
			$query = "INSERT INTO ".categorys."(comp,Category,`Order`,ParentID,SeoKey, TitlePage, Description, KeyWords, SeoH1, SeoH2, SeoP)
			VALUES('".$comp."','".$CatName."','".trim($Order)."','".$PrentID."','".$SeoKey."','".trim($TitlePage)."','".$Description."','".$KeyWords."','".$SeoH1."','".$SeoH2."','".$SeoP."')";
		}
		
		return parent::UpdateInsertMySQL($query);
		
	}
}
?>